﻿using MediatR;
using SystemLYH.API.Application.Command.LocationCommand;
using SystemLYH.Domain;
using SystemLYH.Infrstructre.Impl;
using SystemLYH.Infrstructre.Interface;

namespace SystemLYH.API.Application.Handlers.LocationHandlers
{
    public class LocationCreateHandlers : IRequestHandler<LocationCreateCommand, int>
    {
        protected readonly ILocationRepository _locationRepository;
        /// <summary>
        /// 库位构造函数
        /// </summary>
        /// <param name="locationRepository"></param>
        public LocationCreateHandlers(ILocationRepository locationRepository)
        {
            _locationRepository = locationRepository;
        }

        public async Task<int> Handle(LocationCreateCommand request, CancellationToken cancellationToken)
        {
            return await _locationRepository.CreaseAsync(new Location()
            {
                LocationName = request.LocationName,
                LocationNumber = request.LocationNumber,
                LocationArea = request.LocationArea,
                Locationweight=request.Locationweight,
                WarehouseID = request.WarehouseID,
                LocationState = request.LocationState,
                LocationRemark = request.LocationRemark,
                ReservoirId = request.ReservoirId,
                AddName = "李子坤",
                AddTime = DateTime.Now.ToUniversalTime(),
            });
        }
    }
}
